/*
 * Copyright (c) 2020 Carnegie Lee
 * All rights reserved
 */
package com.geekc.rabbitmq.producer.listener;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * Return消息机制 - 消息是否被路由至相应队列，失败返回
 * @author Carnegie Lee
 */
@Component
public class ReturnCallback implements RabbitTemplate.ReturnCallback {

    /**
     * 需要重写returnedMessage方法
     * @param message 被退回的消息
     * @param replyCode 响应编码
     * @param replyText 响应描述
     * @param exchange 交换机
     * @param routingKey 路由键
     */
    @Override
    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        System.err.println("消息[Code:" + replyCode + ",Text:" + replyText + "]无法路由至正确队列，" +
                "详细信息[exchange:" + exchange + ",routingKey:" + routingKey + ",message:" + message + "]");
        //TODO
    }
}
